jvc.include("jvc.jvcMap");
jvc.ajax=new jvcAjaxClass();
function jvcAjaxClass(){
		this.result="";		
			
	this.docallback=function(callback,j,p1,p2,p3,p4){
				if(!callback)return;
				if (p4)	{ callback(j,p1,p2,p3,p4); return;}
						if (p3)	{ callback(j,p1,p2,p3   ); return;}
						if (p2)	{ callback(j,p1,p2      ); return;}
						if (p1)	{ callback(j,p1         ); return;}					
							callback(j);
}				
		this.submit= function(theForm,callback){	
				this.buildQueryString(theForm,"json_name");						
				this.result	=this.RemoteOperate();
				eval( this.result);
				//alert(json_name);
				this.docallback(callback,json_name);
		}
		this.resultMap=function(){
			var map=new jvcMap();
			try{
				var xmldom = new ActiveXObject("MSXML.DOMDocument");
				xmldom.loadXML(this.result);				
				map.loadXml(xmldom);				
				}catch(e){alert(e);}
				return map;
		}
	
		this.buildQueryString=function(theForm,json_name) 
			{

			  this.URL=theForm.json;
			 
			 var sParam="json_name="+json_name+"&jvcram_temp="+Math.random();
			 var isfirst=false;
			 var url="";
  for(var i = 0; i < theForm.elements.length; i ++ )
      {
         if(theForm.elements[i].name == "")continue;

         if(theForm.elements[i].type == "checkbox")
         {
            var value0 = theForm.elements[i].getAttribute("value0");
            if( ! theForm.elements[i].checked && typeof(value0) == 'undefined')continue;
            if(theForm.elements[i].value == "")continue;
            url += "&";
           
            url += this.encodeParam(theForm.elements[i].name);
            url += "=";
            if(theForm.elements[i].checked)url += this.encodeParam(theForm.elements[i].value);
            else url += this.encodeParam(value0);



         }
         else if(theForm.elements[i].type == "radio")
         {

            // 						 alert(theForm.elements[i].checked + "|" + theForm.elements[i].value);
            if(theForm.elements[i].checked)
            {
               url += "&";
               
               url += this.encodeParam(theForm.elements[i].name);
               url += "=";
               url += this.encodeParam(theForm.elements[i].value);
            }
         }
         else
         {
         url += "&";
          
            url += this.encodeParam(theForm.elements[i].name);
            url += "=";
            var value = theForm.elements[i].value;
          //  if(theForm.elements[i].getAttribute("unfmt"))value = this.format(theForm.elements[i].value, theForm.elements[i].getAttribute("unfmt"));
            url += this.encodeParam(value);
         }
      }
			  sParam+=url+"&jvc.encoding=utf-8";	
			  this.QueryString=sParam;
			};	
			  this.encodeParam = function(str)
			   {
			      return encodeURIComponent(str);
			   }	
		this.RemoteOperate=function()
			{
			       var objXML=this.XMLHTTP();
				   var strPage=this.URL;
				   
				   var strQueryString=this.QueryString;
				   var strURL=strPage;
			     //  objXML.open("post",strURL+"?"+(strQueryString),false);
				  objXML.open("post",strURL,false);
			       objXML.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			       objXML.send(strQueryString);			      
			       var strReturn=objXML.responseText;
			       return strReturn;
			}
						
			this.XMLHTTP=function(){
			      var xmlhttp=false;
			      if(window.XMLHttpRequest) {
			            xmlhttp = new XMLHttpRequest();
			            if (xmlhttp.overrideMimeType)xmlhttp.overrideMimeType("text/xml");			            
			      }
			      else if (window.ActiveXObject){
			            try {xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");}
			            catch (e){
			                 try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}
			                  catch (e){alert('error');}
			            }
			      }
			   return xmlhttp;
			};			
}
